<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %> 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>测试到MySQL数据链接</title>
</head>
<body>
	<%
    String driverName="com.mysql.jdbc.Driver"; 
	//数据库用户名 
	String userName="bradden"; 
	//密码 
	String userPasswd="466123"; 
	//数据库名 
	String dbName="roombook";
	
	//防止出现中文乱码，需要添加字符编码格式
	String DBUrl = "jdbc:mysql://localhost/"+dbName+"?characterEncoding=utf8";
	
	Connection conn = null;
	PreparedStatement ps = null;
	try {
		Class.forName(driverName).newInstance();
		
		conn = DriverManager.getConnection(DBUrl,userName,userPasswd);

		//创建查询字符串,获取id=4的记录
		String sql = "UPDATE `room_8-1115` SET  `title`=? ,`content`=? WHERE `id`=?;";
		
		//创建预处理语句对象
		ps = conn.prepareStatement(sql);
		ps.setString(1,"信科的会议");
		ps.setString(2,"此房间将占用two hours");
		ps.setInt(3,104);
		
		int  i = ps.executeUpdate();
		out.print("成功更新"+i+"行记录！");
	}
		catch (Exception e) {
		e.printStackTrace();
	}
	finally
	{
		//关闭状态
		ps.close();
		//关闭数据库
		conn.close();
	}
	%>
</body>
</html>